package com.dc.dao;

import com.dc.dao.vo.CalibrationShipOldReturnVO;
import com.dc.entity.CalibrationShipOldEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CalibrationShipOldDao extends JpaRepository<CalibrationShipOldEntity, Long>, JpaSpecificationExecutor<CalibrationShipOldEntity> {

    @Query(nativeQuery = true,
            value = "SELECT " +
                    " tcsc.id AS id," +
                    " tcsc.ship_id as shipId," +
                    " ts.name as shipName," +
                    " tcsc.length as length," +
                    " tcsc.start_time as startTime," +
                    " tcsc.end_time as endTime," +
                    " tcsc.cut_num as cutNum," +
                    " tcsc.start_gas as startGas," +
                    " tcsc.end_gas as endGas," +
                    " tcsc.gas as gas," +
                    " tcsc.gas_by_unit as gasByUnit," +
                    " tcsc.start_o2 as startO2," +
                    " tcsc.end_o2 as endO2," +
                    " tcsc.o2 as o2," +
                    " tcsc.o2_by_unit as o2ByUnit " +
                    " FROM " +
                    " t_calibration_ship_old tcsc JOIN t_ship ts ON tcsc.ship_id = ts.id")
    public List<CalibrationShipOldReturnVO> findAllOld();

    @Query(nativeQuery = true,
            value = "SELECT " +
                    " tcsc.id AS id," +
                    " tcsc.ship_id as shipId," +
                    " ts.name as shipName," +
                    " tcsc.length as length," +
                    " tcsc.start_time as startTime," +
                    " tcsc.end_time as endTime," +
                    " tcsc.cut_num as cutNum," +
                    " tcsc.start_gas as startGas," +
                    " tcsc.end_gas as endGas," +
                    " tcsc.gas as gas," +
                    " tcsc.gas_by_unit as gasByUnit," +
                    " tcsc.start_o2 as startO2," +
                    " tcsc.end_o2 as endO2," +
                    " tcsc.o2 as o2," +
                    " tcsc.o2_by_unit as o2ByUnit " +
                    " FROM " +
                    " t_calibration_ship_old tcsc JOIN t_ship ts ON tcsc.ship_id = ts.id",
            countQuery = "SELECT count(1) from t_calibration_ship_old tcsc JOIN t_ship ts ON tcsc.ship_id = ts.id")
    public Page<CalibrationShipOldReturnVO> findAllByPage(Pageable pageable);

}
